{extend name="public:common_edit"/}
{block name="main"}
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-list"></i> {$title}</h3>
        </div>
        <div class="panel-body">
            <div class="navbar navbar-default">
                <form action="" id="search-form2" class="navbar-form form-inline" method="get" onsubmit="return false">
                    <div class="form-group">

                        <label class="control-label" for="input-order-id">菜单分类</label>
                        {:arr2select('pid',$cate,'全部',input('pid'),'id','name')}

                    </div>

                    <button type="submit" onclick="javascript:document.getElementById('search-form2').submit();"
                            id="button-filter search-order" class="btn btn-primary"><i class="fa fa-search"></i> 筛选
                    </button>

                    {if !is_numeric(input('pid'))}
                    <a href="javascript:;" onclick="add()" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加菜单</a>
                    {/if}
                </form>
            </div>
            <div id="ajax_return">
                <form method="post" action="{:url('Nav/order')}" enctype="multipart/form-data" target="_blank" id="form-order">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <td width="5%">排序</td>
                                <td>菜单名</td>
                                <td>控制器</td>
                                <td>方法</td>
                                <td>icon</td>
                                <td>显示(1)/隐藏(0)</td>
                                <td>操作</td>
                            </tr>
                            </thead>
                            <tbody>
                            <!-- 列表循环开始 -->
                            {volist name="rows" id="row" key="key"}
                            <tr>
                                <td><input class="form-control" style="width:40px;height:25px;" type="text" name="{$row['id']}"
                                           value="{$row['sort']}"></td>
                                <td>{$row['_name']}</td>
                                <td>{$row['control']}</td>
                                <td>{$row['act']}</td>
                                <td>{$row['icon']}</td>
                                <td>{$row['status']}</td>
                                <td>
                                    <a class="btn btn-primary" href="javascript:;" navId="{$row['id']}" navName="{$row['name']}"  onclick="add_child(this)">添加子菜单</a>
                                    <a class="btn btn-primary" href="javascript:;" navStatus="{$row['status']}" navId="{$row['id']}" navName="{$row['name']}" controller="{$row['control']}" navMca="{$row['act']}" navIco="{$row['icon']}" onclick="edit(this)">修改</a>
                                    <span class="btn-danger btn check_del" data-url="{:url('Nav/delete',array('id'=>$row['id']))}?returnPid={:input('pid')}" >删除</span>
                                </td>
                            </tr>
                            {/volist}
                            <!-- 列表循环结束 -->
                            </tbody>
                        </table>
                    </div>
                    <tr>
                        <th><input class="btn btn-success submit" type="submit" value="排序"></th>
                        <td></td>
                        <td></td>
                    </tr>
                </form>
            </div>

        </div>
    </div>

<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                <h4 class="modal-title" id="myModalLabe"> 添加菜单</h4></div>
            <div class="modal-body">
                <form id="bjy-form" class="form-inline" action="{:url('Nav/add')}?returnPid={:input('pid')}" method="post"><input
                        type="hidden" name="pid" value="0">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <th width="12%">菜单名：</th>
                            <td><input class="form-control" type="text" name="name"></td>
                        </tr>
                        <tr>
                            <th>控制器：</th>
                            <td><input class="form-control" type="text" name="control"> 方法即可 例如 nav
                            </td>
                        </tr>
                        <tr>
                            <th>方法：</th>
                            <td><input class="form-control" type="text" name="act"> 方法即可 例如 index
                            </td>
                        </tr>

                        <tr>
                            <th>状态：</th>
                            <td><input class="form-control" type="text" name="status"> 显示(1)/隐藏(0)
                            </td>
                        </tr>
                        <tr>
                            <th>图标：</th>
                            <td><input class="form-control" type="text" name="icon"> glyphicon图标 输入 glyphicon-后边的即可</td>
                        </tr>
                        <tr>
                            <th></th>
                            <td><input class="btn btn-success submit" type="submit" value="添加"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
                <h4 class="modal-title" id="myModalLabel"> 修改菜单</h4></div>
            <div class="modal-body">
                <form id="bjy-" class="form-inline" action="{:url('Nav/edit')}?returnPid={:input('pid')}" method="post"><input
                        type="hidden" name="id">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <th width="12%">菜单名：</th>
                            <td><input class="form-control" type="text" name="name"></td>
                        </tr>
                        <tr>
                            <th>控制器：</th>
                            <td><input class="form-control" type="text" name="control"> 方法即可 例如 nav
                            </td>
                        </tr>
                        <tr>
                            <th>方法：</th>
                            <td><input class="form-control" type="text" name="act"> 输入方法即可 例如 /Nav/index
                            </td>
                        </tr>

                        <tr>
                            <th>状态：</th>
                            <td><input class="form-control" type="text" name="status"> 显示(1)/隐藏(0)
                            </td>
                        </tr>
                        <tr>
                            <th>图标：</th>
                            <td><input class="form-control" type="text" name="icon"> glyphicon图标 输入 glyphicon-后边的即可</td>
                        </tr>
                        <tr>
                            <th></th>
                            <td><input class="btn btn-success submit" type="submit" value="修改"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>


{/block}

{block name="js"}
<script>

    // 添加菜单
    function add() {
        $("input[name='name'],input[name='act'],input[name='control'],input[name='status']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj) {
        var navId = $(obj).attr('navId');
        $("input[name='pid']").val(navId);
        $("input[name='name']").val('');
        $("input[name='status']").val('');
        $("input[name='url']").val('');
        $("input[name='icon']").val('');
        $("input[name='controller']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj) {
        var navId     = $(obj).attr('navId');
        var navName   = $(obj).attr('navName');
        var navStatus  = $(obj).attr('navStatus');
        var navMca = $(obj).attr('navMca');
        var navIco = $(obj).attr('navIco');
        var controller = $(obj).attr('controller');
        $("input[name='id']").val(navId);
        $("input[name='control']").val(controller);
        $("input[name='name']").val(navName);
        $("input[name='status']").val(navStatus);
        $("input[name='act']").val(navMca);
        $("input[name='icon']").val(navIco);
        $('#bjy-edit').modal('show');
    }

</script>



{/block}



